package com._常用API;

import java.util.Date;

/**
 * @author liyiruo
 * @Description
 * @Date 2024/2/28 上午9:08
 */
public class TestMain {


    public static void main(String[] args) {

        TestMain main = new TestMain();
//        main.myfun(1);
//        System.out.println("000000000000000000000000000000");
//        main.myfun(2);




        Thread thread1=new Thread(new Runnable() {
            @Override
            public void run() {
                main.myfun2(3);
            }
        });


        Thread thread2=new Thread(new Runnable() {
            @Override
            public void run() {
                main.myfun2(4);
            }
        });

        thread1.start();
        thread2.start();
    }

    public synchronized void myfun2(int flag) {

        System.out.println("myfun2====>" + flag);
        System.out.println(System.currentTimeMillis()+ " "+flag);


        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


    }


    public synchronized void myfun(int flag) {

        System.out.println("main: " + Thread.currentThread().getName());
        System.out.println("=========开始===========: " + flag);
        final int a = 100;
        Thread thread = new Thread(new Runnable() {
            int b = a;

            @Override
            public void run() {
                System.out.println("run==>: " + Thread.currentThread().getName());

                try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                b = a + 10;
                System.out.println("--------中间----------" + b + "" + flag);

            }
        });


        thread.start();
        System.out.println("main: " + Thread.currentThread().getName());
        System.out.println("============结束==============flag " + flag);

    }



    class myRun implements Runnable{
        /**
         * When an object implementing interface <code>Runnable</code> is used
         * to create a thread, starting the thread causes the object's
         * <code>run</code> method to be called in that separately executing
         * thread.
         * <p>
         * The general contract of the method <code>run</code> is that it may
         * take any action whatsoever.
         *
         * @see Thread#run()
         */
        @Override
        public void run() {

        }
    }
}
